<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>~/MySrc/BlogCode/2010-3-2/MacPasteboardTest/MacPasteboardTestAppDelegate.m.html</title>
<meta name="Generator" content="Vim/7.2">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#ffffff" text="#000000"><font face="monospace">
<font color="#0000ee"><i>//</i></font><br>
<font color="#0000ee"><i>//&nbsp;&nbsp;MacPasteboardTestAppDelegate.m</i></font><br>
<font color="#0000ee"><i>//&nbsp;&nbsp;MacPasteboardTest</i></font><br>
<font color="#0000ee"><i>//</i></font><br>
<font color="#0000ee"><i>//&nbsp;&nbsp;Created by JTianLing on 3/3/10.</i></font><br>
<font color="#0000ee"><i>//&nbsp;&nbsp;Copyright 2010 JTianLing. All rights reserved.</i></font><br>
<font color="#0000ee"><i>//</i></font><br>
<br>
<font color="#1874cd">#import </font><font color="#4a708b">&quot;MacPasteboardTestAppDelegate.h&quot;</font><br>
<br>
<font color="#b03060"><b>@implementation</b></font>&nbsp;MacPasteboardTestAppDelegate<br>
<br>
@synthesize window;<br>
@synthesize textField;<br>
<br>
<font color="#458b74">- </font>(<font color="#008b00"><b>void</b></font>)applicationDidFinishLaunching:(NSNotification *)aNotification {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ee"><i>// Insert code here to initialize your application</i></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ee"><i>// notice!It's ugly but legality.</i></font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NSStringPboardType = NSHTMLPboardType;<br>
}<br>
<br>
<font color="#458b74">- </font>(<font color="#008b00"><b>void</b></font>)writeToPasteboard:(NSPasteboard *)pb withString:string{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[pb declareTypes:[NSArray arrayWithObject:NSStringPboardType]<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; owner:<font color="#b03060"><b>self</b></font>];<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[pb setString:string forType:NSStringPboardType];<br>
}<br>
<br>
<font color="#458b74">- </font>(<font color="#008b00"><b>BOOL</b></font>)readFromPasteboard:(NSPasteboard *)pb {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NSArray *types = [pb types];<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#b03060"><b>if</b></font>&nbsp;([types containsObject:NSStringPboardType]) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NSString *value = [pb stringForType:NSStringPboardType];<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[[<font color="#b03060"><b>self</b></font>&nbsp;textField] setStringValue:value];<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#b03060"><b>return</b></font>&nbsp;YES;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#b03060"><b>return</b></font>&nbsp;NO;<br>
}<br>
<br>
<font color="#458b74">- </font>(IBAction)cut:(<font color="#008b00"><b>id</b></font>)sender {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[<font color="#b03060"><b>self</b></font>&nbsp;copy:sender];<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[[<font color="#b03060"><b>self</b></font>&nbsp;textField] setStringValue:<font color="#4a708b">@&quot;&quot;</font>];<br>
}<br>
<br>
<font color="#458b74">- </font>(IBAction)copy:(<font color="#008b00"><b>id</b></font>)sender {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NSPasteboard *pb = [NSPasteboard generalPasteboard];<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[<font color="#b03060"><b>self</b></font>&nbsp;writeToPasteboard:pb withString:[textField stringValue]];<br>
}<br>
<br>
<font color="#458b74">- </font>(IBAction)paste:(<font color="#008b00"><b>id</b></font>)sender {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NSPasteboard *pb = [NSPasteboard generalPasteboard];<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#b03060"><b>if</b></font>( ![<font color="#b03060"><b>self</b></font>&nbsp;readFromPasteboard:pb] ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NSBeep();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
}<br>
<br>
<font color="#b03060"><b>@end</b></font><br>
</font></body>
</html>
